<template name="sidebarItemIcon">
	{{#if icon}}
		<div class="{{#if isRoom}}sidebar-item__room-type{{else}}sidebar-item__icon{{/if}} {{#if status}}sidebar-item__icon-status--{{status}}{{/if}}">
			{{> icon block="rc-icon--default-size sidebar-item__icon sidebar-item__icon" icon=icon}}
		</div>
	{{else}}
		{{# userPresence uid=uid}}<div class="sidebar-item__user-status {{#if status}}sidebar-item__user-status--{{status}}{{/if}}" aria-label="{{status}}"></div>{{/userPresence}}
	{{/if}}
</template>

<template name="sidebarItem">
	<li class="sidebar-item{{#if showUnread }} sidebar-item--unread{{/if}}{{#if active}} sidebar-item--active{{/if}}{{#if toolbar}} popup-item{{/if}} js-sidebar-type-{{t}}" data-id="{{_id}}">
		<a class="sidebar-item__link" href="{{#if route}}{{route}}{{else}}{{pathFor pathSection group=pathGroup}}{{/if}}" aria-label="{{name}}">
			{{#unless isLivechatQueue}}

				<div class=" {{#if isRoom}}sidebar-item__picture{{else}}sidebar-item-option-icon{{/if}}">
					{{#if darken}}
						{{#if icon}}
							<div class="{{#if isRoom}}sidebar-item__room-type{{else}}sidebar-item__icon{{/if}}">
								{{> icon block="sidebar-item__icon rc-icon--default-size" icon=icon}}
							</div>
						{{/if}}
					{{else}}
						<div class="sidebar-item__user-thumb">
							{{> avatar url=avatar roomIcon=icon lazy=true}}
						</div>
					{{/if}}
				</div>
			{{/unless}}
			<div class="sidebar-item__body">
				{{# let extended=isExtendedViewMode}}
				<div class="sidebar-item__message">
					<div class="sidebar-item__message-top">
						<div class="sidebar-item__name">
							{{#unless darken}}
								{{> sidebarItemIcon}}
							{{/unless}}

							<div class="sidebar-item__ellipsis">
								{{name}}
								{{#if mySelf}}
									<span class="sidebar-item__me">({{_ "You"}})</span>
								{{/if}}
							</div>
							{{#if streaming}} {{>icon icon="video" block="sidebar-item__video pulse"}} {{/if}}
						</div>
						{{#if extended}}
							{{#if lastMessageTs}}
								<span class="sidebar-item__time">{{lastMessageTs}}</span>
							{{/if}}
						{{/if}}
					</div>
					<div class="sidebar-item__message-bottom">
						{{#if extended}}
							{{#if lastMessage}}
								<div class="sidebar-item__last-message">
									<span class="message-body--unstyled">{{{lastMessage}}}</span>
								</div>
							{{/if}}
						{{/if}}
						{{#if unread}}
							<span class="{{badgeClass}}">{{unread}}</span>
						{{/if}}
					</div>
				</div>
				{{/let}}

				{{#if isRoom}}
					<div class="sidebar-item__menu" aria-haspopup="true">
						{{> icon block="sidebar-item__menu-icon rc-icon--default-size" icon="menu"}}
					</div>
				{{/if}}
			</div>
		</a>
	</li>
</template>
